from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
import ddddocr
import base64
ocr = ddddocr.DdddOcr()
app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)
class Image(BaseModel):
    url: str
@app.post("/recognizeVerifyCode/")
async def recognize_image(image: Image):
    try:
        image_data = base64.b64decode(image.url.split(",")[1])
        result = ocr.classification(image_data)
        print(result)
        return {"result": result}
    except Exception as e:
        print(e)
        return {"result": str(e)}
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=5711)